package com.yyl.rbacs.config;

import com.yyl.rbacs.shiro.ShiroTag;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @BelongsProject: rbacs
 * @BelongsPackage: com.yyl.rbacs.config
 * @Author: YuanSir
 * @CreateTime: 2022-10-28  11:08
 * @Description:
 * @Version: 1.0
 */


@Configuration
public class FreemarkerConfig {
    
    @Bean
    public FreeMarkerConfigurer freeMarkerConfigurer(ShiroTag shiroTag){
        FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
        
        //1. 配置freemarker模板的路径
        configurer.setTemplateLoaderPath("classpath:/templates");
        
        //2. 配置freemarker可以解析的shiroTag
        //即<#if shiro.hasPermission("sys:role:update")>
        Map<String, Object> variables = new HashMap<>(1);
        variables.put("shiro", shiroTag);
        configurer.setFreemarkerVariables(variables);
        
        Properties settings = new Properties();
        settings.setProperty("default_encoding", "utf-8");
        settings.setProperty("number_format", "0.##");
        configurer.setFreemarkerSettings(settings);
        return configurer;
    }

}
